import itertools

def check_arithmetic(seq):
    if len(seq) < 3:
        return False
    diff = seq[1] - seq[0]
    for i in range(2, len(seq)):
        if seq[i] - seq[i-1] != diff:
            return False
    return True

def check_geometric(seq):
    if len(seq) < 3 or seq[0] == 0:
        return False
    ratio = seq[1] / seq[0]
    for i in range(2, len(seq)):
        if seq[i-1] == 0 or seq[i] / seq[i-1] != ratio:
            return False
    return True

def main():
    try:
        numbers = []
        for i in range(5):
            num = float(input(f"请输入第{i+1}个数字: "))
            numbers.append(num)
    except ValueError:
        print("输入无效，请输入有效的数字。")
        return

    diffs = []
    for a, b in itertools.combinations(numbers, 2):
        diffs.append(abs(a - b))
    
    # 检查所有三元组
    has_arithmetic = False
    has_geometric = False
    for triplet in itertools.combinations(diffs, 3):
        sorted_triplet = sorted(triplet)
        if check_arithmetic(sorted_triplet):
            has_arithmetic = True
        if check_geometric(sorted_triplet):
            has_geometric = True

    print("\n两两之间的差:")
    for a, b in itertools.combinations(numbers, 2):
        print(f"{a} 和 {b} 的差: {abs(a - b)}")

    if has_arithmetic:
        print("\n存在等差数列！")
    else:
        print("\n不存在等差数列。")

    if has_geometric:
        print("存在等比数列！")
    else:
        print("不存在等比数列。")

if __name__ == "__main__":
    main()    